home *** CD-ROM | disk | FTP | other *** search
- Path: susx.ac.uk!mattst
- From: mattst@cogs.susx.ac.uk (Matthew Stanfield)
- Newsgroups: comp.lang.c
- Subject: Re: C coding standards
- Date: 14 Mar 1996 17:45:36 GMT
- Organization: University of Sussex
- Distribution: world
- Message-ID: <4i9m00$aqi@infa.central.susx.ac.uk>
- References: <313B4548.45AA@oc.com> <DnuLzM.8xr@gti-ia.nl>
- NNTP-Posting-Host: tsunx.ctn.cogs.susx.ac.uk
- X-Newsreader: TIN [version 1.2 PL2]
-
- Paul Wallis (paulw@gti-ia.nl) wrote:
- : Teresa Reiko wrote:
- : > In this book and others, notably 'Code Complete', these programming
- : > guides published by Microsoft Press, it is evident why Microsoft put
- : > so many bugs in Windows 95. Here are the three worst Microsoft
- : > coding rules, in my opinion at least:
- : >
- : > Every line of code must contain a comment.
- : > Any number greater than 2 must be a named constant.
- : > No procedure may be longer than 25 lines.
- : >
- : > If you follow these rules, you can be sure to write buggy, inefficient
- : > code that is difficult to revise and will generally look 'dirty'.
- : > Of course, if this is your intent, that's OK, but...
- : >
- : I am sorry, but I feel compelled to answer this, even though the debate does NOT
- : belong in this newsgroup. I believe IMHO that you have maligned an excellent book.
- : I have read this book cover to cover and agreed with 90% of what the author says.
- : And before you go on to 'slate' me, I think you aught to re-read the book and actually
- : look at what is said.
-
- : The Code Complete definately does not say that every line should have a comment.
- : In fact it says that you should be able to read what the code is meant to do without
- : resorting to comments every line. The author tries to put across the idea that
- : comments bear a purpose and are not a cross to be born.
-
- : It suggests that a _guideline_ to function length would be one page long; going on
- : to say that a page could be 25 lines 60 lines or even 120 lines depending upon wha
- : you use for display.
-
- : As for ridiculing the fact that numbers greater than 2 should be a named constant.
- : I really can't see your argument there. It has, as far as I'm aware, always been
- : common practice in the 'C' programming community to write:
-
- : #define NAME_LIMIT 39
- : char name[NAME_LIMIT];
-
- : as opposed to:
-
- : char name[39];
-
- : And IMHO the former is far easier to read an when you wish to upgrade or modify the
- : length of a name you only have to change the #define as opposed to searching through
- : all of your code for the number 39 and doing a replace...
-
- : Regards,
- : Paul
-
- Listen to what Paul says Teresa, he knows what he's talking about.
-
- As for Code Complete -- it rules okay, you should re-read and think about
- why what he says is sound. From what you've said I bet you've never maintained
- anybody else's code and wished that they had read Code Complete.
-
- BTW did you do a CS or similar degree? No - what a surprise.
-
- Matt
-
- |------------------------------------------------|
- | ,\\///, Matthew Stanfield ,\\\//, |
- | O | O Cognitive Sciences O | O |
- | | University of Sussex | |
- | \-+-/ mattst@cogs.susx.ac.uk \-+-/ |
- |------------------------------------------------|
-